// pages/travelAgency/travelAgencyDetail.js
var Tool = require("../../utils/ztool.js");
var tool = new Tool();
var util = require('../../utils/util.js');
var traveldetail;
var cardetail;
var billIDD = '';
var pricother = '';
// var price = '';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IDD: '',
    list: [],
    listChengke: [],
    listGuider: [],
    price: '',
    // billIDD:'',
    //订单错误标识
    order_error: false,
    winHeight: 0,
    //弹出框标识
    hiddenmodalput: true,
    //picker
    routeStatusIndex: 0,
    routeArray: [
      {
        id: 0,
        name: '未确认'
      },
      {
        id: 1,
        name: '已确认'
      },
      {
        id: 2,
        name: '已取消'
      }
    ],
    selectTagChengke: 0,
    newselectTagChengke: 0,

    //手输的三个参数
    newpassengername: '',
    newpassengertel: '',
    newpassengerprice: '',

    listChengkeAdd: [],
    listChengkeAddSearch: [],
    //弹出框标识
    hiddenChengke: true,
    ChengkeID: '',
    ChengkeName: '',
    ChengkePrice: '',
    selectTagGuider: 0,
    hideModalGuider: true,
    listGuiderAdd: [],
    listGuiderAddSearch: [],
    GuiderID: '',
    hiddenGuiderChange: true,
    GuiderChangePrice: '',
    GuiderIDChangePrice: '',
    hiddenGuider: true,
    GuiderPrice: '',
    GuiderName: '',
    GuiderIDNew: '',
    selectTagDelete: 0,
    listDelete: [],
    listDeleteSearch: [],
    selectTagAdd: 0,
    listGuiderPartnerAdd: [],
    listGuiderPartnerAddSearch: [],
    GuiderTel: '',
    hiddenDriver: true,
    changeDriverName: '',
    changeDriverPrice: '',
    changeDriverPrice2: '',
    changeDriverID: '',
    DriverTel: '',

  },

  onShareAppMessage: function (res) {
    var useinfo = wx.getStorageSync('userInfo');
    console.log(useinfo)
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '您有来自' + useinfo.UCompanyName + '的新订单！',
      path: 'pages/jumppage/jumppage?jumproutetitle=' + this.data.traveldetail.routeTitle + '&jumpCompanyName=' + useinfo.UCompanyName + '&jumpshangchedidian=' + this.data.traveldetail.GetOnPlace + '&jumpxiachedidian=' + this.data.traveldetail.GetOffPlace + '&jumpstartime=' + this.data.traveldetail.UseCarStartTime + '&jumpendtime=' + this.data.traveldetail.UseCarEndTime + '&jumprouteroute=' + this.data.traveldetail.Route,
      imageUrl: '../../images/pushlogo2.png',
      success: function (res) {
        // 转发成功
        wx.showToast({
          title: '转发成功',
          icon: 'succes',
          duration: 1000,
          mask: true
        })
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },

  callPhone: function (e) {
    if (e.currentTarget.id == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id //仅为示例，并非真实的电话号码
    });
  },

  bindPickerChange: function (e) {
    console.log(e)
    // var carStatus = e.currentTarget.dataset.carStatus
    var QuotePrice = e.currentTarget.dataset.quoteprice
    var HopePrice = e.currentTarget.dataset.hopeprice
    console.log(QuotePrice)
    console.log(HopePrice)
    console.log(e.detail.value)
    if (this.data.traveldetail.CarCompanyID != -1) {
      if (QuotePrice != HopePrice && e.detail.value == 1) {
        this.showError('双方价格不平，不能确认订单')
        return
      }
    }
    // console.log(carStatus,QuotePrice,HopePrice)
    // if (carStatus==1){
    //   if(!QuotePrice==HopePrice){

    //     return
    //   }
    // }
    this.setData({
      routeStatusIndex: e.detail.value
    }),
      changeOrderState(e.detail.value, this)
    // getServiceData(this)
  },
  bindchangeprice: function (e) {
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput,

    })
    this.setData({
      price: ''
    })
    console.log(this.data.price)
  },
  cancel: function () {
    this.setData({
      hiddenmodalput: true
    });
  },

  confirm: function () {
    // console.log(price);
    console.log(pricother);
    this.setData({
      hiddenmodalput: true
    })
    changePrice(this)
    // getServiceData(this)
  },

  checkboxChange: function (e) {
    pricother = '';
    console.log(e)
    if (e.detail.value == true) {
      pricother = 1;
    } else {
      pricother = 0;
    }
    console.log(pricother)
  },

  inputchange: function (e) {
    var pri = e.detail.value
    this.data.price = pri;
  },

  cancelor: function (e) {

    var iscancel = e.currentTarget.dataset.status
    var tel = e.currentTarget.dataset.telnum
    cancelorhuifu(this, e.currentTarget.id)

    //推送
    this.CancelPushToGuider(tel, iscancel)
  },

  addDriverJump: function (e) {
    var Idd = e.currentTarget.id

    var pages = getCurrentPages()
    var backpage = pages[pages.length - 2]
    backpage.setData({
      backtag: 1,
    });

    wx.navigateTo({
      url: '../travelAgency/addDriver?IDD=' + Idd,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  //修改订单跳转
  changeOrder: function (e) {
    var date = new Date(this.data.traveldetail.UseCarEndTime)
    var time1 = date.getTime()

    var nowdate = new Date();
    var time2 = nowdate.getTime()
    console.log(time2);
    if (time1 < time2) {
      this.showError('已过期订单不能修改')
      return;
    }

    var Idd = this.data.IDD
    wx.navigateTo({
      url: '../travelAgency/travelOrderAdd/travelOrderAdd?IDD=' + Idd,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },


  newaddchengke: function () {
    this.setData({
      newselectTagChengke: 1,
    });
  },

  hidenewaddchengke: function () {
    this.setData({
      newselectTagChengke: 0,
      newpassengername: '',
      newpassengertel: '',
      newpassengerprice: '',
    });
  },

  //添加乘客时的三个input方法
  newinputpassengername: function (e) {
    this.setData({
      newpassengername: e.detail.value,
    });
  },

  newinputpassengertel: function (e) {
    this.setData({
      newpassengertel: e.detail.value,
    });
  },

  newinputpassengerprice: function (e) {
    this.setData({
      newpassengerprice: e.detail.value,
    });
  },

  addnewchengke: function () {
    var that = this
    console.log(that.data.newpassengername)
    console.log(that.data.newpassengertel)
    console.log(that.data.newpassengerprice)

    if (that.data.newpassengername == '') {
      that.showError('请输入乘客姓名')
      return
    }

    if (that.data.newpassengertel == '') {
      that.showError('请输入乘客电话')
      return
    }

    if (that.data.newpassengertel.length != 11) {
      that.showError('请输入正确的手机号码')
      return
    }

    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (!myreg.test(that.data.newpassengertel)) {
      that.showError('请输入正确的手机号码')
      return
    }

    if (that.data.newpassengerprice == '') {
      that.data.newpassengerprice = '0'
    }

    var userInfo = wx.getStorageSync('userInfo');

    wx.request({
      url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddCoopPartners.ashx',
      data: {
        ID: userInfo.ID,
        PID: 0,
        Type: '4',
        OpType: '0',
        Price: that.data.newpassengerprice,
        ctel: that.data.newpassengertel,
        cname: that.data.newpassengername,
        IDD: that.data.IDD
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        // success

        var data = tool.getRegularJson(res.data);
        var code = data.code;
        console.log(res);
        if (code == 0) {

          wx.showToast({
            title: '添加成功',
            icon: 'success',
            duration: 1000
          })
          that.setData({
            newselectTagChengke: 0,
            newpassengername: '',
            newpassengertel: '',
            newpassengerprice: '',
          });
          setTimeout(function deletesuccess() {
            getDataChengke(that)
          }, 1000);

          // that.CancelPushToGuider(tel, 0)

          // var pages = getCurrentPages()
          // var backpage = pages[pages.length - 2]
          // backpage.setData({
          //   backtag: 1,
          // });
        } else {
          that.showError(data.msg)
        }
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })

  },

  //添加乘客弹框隐藏
  addChengke: function () {
    getDataChengkeAdd(this)
    this.setData({
      selectTagChengke: 1,
      newselectTagChengke: 0,
      newpassengername: '',
      newpassengertel: '',
      newpassengerprice: '',
      // listChengkeAdd: [],
      // listChengkeAddSearch: []
    });
  },

  hideModalChengke: function () {
    this.setData({
      selectTagChengke: 0,
      // listChengkeAdd: [],
      // listChengkeAddSearch: []
    })
  },

  inputsearchChengke: function (e) {
    var that = this
    var arr = []
    var keyWord = e.detail.value

    for (var i = 0; i < that.data.listChengkeAddSearch.length; i++) {
      if (that.data.listChengkeAddSearch[i].cName.indexOf(keyWord) >= 0 || that.data.listChengkeAddSearch[i].cTel.indexOf(keyWord) >= 0) {
        arr.push(that.data.listChengkeAddSearch[i]);
      }
    }
    if (keyWord != null && keyWord != undefined && keyWord != '' && keyWord != ' ' && keyWord.length != 0) {
      if (arr.length == 0) {
        wx.showToast({
          title: '没有对应的乘客',
          icon: 'none',
          duration: 1000,
        })
      }
      that.setData({
        listChengkeAdd: arr,
      });
    } else {
      that.setData({
        // listChengkeAdd: that.data.listChengkeAddSearch,
        listChengkeAdd: []
      });
    }
  },

  ChengkeToOrder: function (e) {
    this.data.ChengkeID = ''
    this.data.ChengkeName = ''
    this.data.GuiderTel = ''
    this.setData({
      ChengkePrice: '',
      hiddenChengke: false,
      selectTagChengke: 0,
      ChengkeID: e.currentTarget.dataset.idx,
      ChengkeName: e.currentTarget.dataset.namex,
      GuiderTel: e.currentTarget.dataset.telnum,
    });
  },

  cancelChengke: function () {
    this.setData({
      hiddenChengke: true
    });
  },

  confirmchengke: function () {
    if (!this.data.ChengkePrice) {
      this.data.ChengkePrice = '0'
      // this.showError('请输入报价')
      // return
    }
    this.setData({
      hiddenChengke: true
    })
    pullChengkeToOrder(this)
  },

  inputchengkePrice: function (e) {
    this.data.ChengkePrice = e.detail.value
  },
  //取消导游
  cancelGuider: function (e) {
    var GuiderID = e.currentTarget.id
    var iscancel = e.currentTarget.dataset.status
    var tel = e.currentTarget.dataset.telnum
    cancelORGuider(this, GuiderID)

    //推送
    this.CancelPushToGuider(tel, iscancel)
  },
  //导游修改报价弹窗
  changeGuiderPrice: function (e) {
    var cancel = e.currentTarget.dataset.cancel
    console.log(cancel)
    if (cancel == 1) {
      this.showError('导游已取消不可修改')
    } else {
      this.setData({
        GuiderIDChangePrice: e.currentTarget.dataset.idx,
        GuiderChangePrice: '',
        hiddenGuiderChange: false,
        DriverTel: e.currentTarget.dataset.tel,

      })
    }
  },

  cancelGuiderChange: function () {
    this.setData({
      hiddenGuiderChange: true
    });
  },
  //导游确定修改报价
  confirmGuiderChange: function () {
    GuiderChangePriceFun(this)
    this.setData({
      hiddenGuiderChange: true
    });


  },
  //修改导游报价的input
  inputGuiderChangePrice: function (e) {
    this.data.GuiderChangePrice = e.detail.value
  },

  //添加导游弹框
  addGuider: function () {
    getDataGuiderAdd(this)
    this.setData({
      selectTagGuider: 1,
      // listChengkeAdd: [],
      // listChengkeAddSearch: []
    });
  },
  //隐藏导游弹框
  hideModalGuider: function () {
    this.setData({
      selectTagGuider: 0
    });
  },
  //导游搜索
  inputsearchGuider: function (e) {
    var that = this
    var arr = []
    var keyWord = e.detail.value

    for (var i = 0; i < that.data.listGuiderAddSearch.length; i++) {

      if (that.data.listGuiderAddSearch[i].PartnerName.indexOf(keyWord) >= 0 || that.data.listGuiderAddSearch[i].PartnerTel.indexOf(keyWord) >= 0) {
        arr.push(that.data.listGuiderAddSearch[i]);
      }
    }
    if (keyWord != null && keyWord != undefined && keyWord != '' && keyWord != ' ' && keyWord.length != 0) {
      if (arr.length == 0) {
        wx.showToast({
          title: '没有对应的导游',
          icon: 'none',
          duration: 1000,
        })
      }
      that.setData({
        listGuiderAdd: arr,
      });
    } else {
      that.setData({
        listGuiderAdd: that.data.listGuiderAddSearch
      });
    }
  },


  //导游拉入订单
  GuiderToOrder: function (e) {
    this.setData({
      GuiderPrice: '',
      selectTagGuider: 0,
      GuiderName: e.currentTarget.dataset.namex,
      GuiderIDNew: e.currentTarget.dataset.idx,
      GuiderTel: e.currentTarget.dataset.telnum,
      hiddenGuider: false
    })
  },

  cancelGuiderPrice: function () {
    this.setData({
      hiddenGuider: true
    })
  },
  //输入报价后确定将导游拉入
  confirmGuiderPrice: function () {
    pullGuiderToOder(this)
    this.setData({
      hiddenGuider: true
    })
  },
  //导游报价输入框
  inputGuiderPrice: function (e) {
    this.data.GuiderPrice = e.detail.value
  },

  hideModalDelete: function () {
    this.setData({
      selectTagDelete: 0,
    });
  },

  deleteGuider: function () {
    this.data.listDelete = []
    this.data.listDeleteSearch = []
    this.setData({
      listDelete: this.data.listGuiderAdd,
      listDeleteSearch: this.data.listGuiderAdd,
      selectTagDelete: 1,
      selectTagGuider: 0
    });
  },

  //移除合作导游
  RemovePartnerGuider: function (e) {
    var that = this
    var guiderName = e.currentTarget.dataset.namex
    var guiderID = e.currentTarget.dataset.idx
    wx: wx.showModal({
      title: '确定删除？',
      content: '确定移除此合作导游(' + guiderName + ')吗',
      showCancel: true,
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          deletePartnerGuider(that, guiderID)
        } else {

        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  //删除合作导游搜索
  inputsearchDelete: function (e) {
    var that = this
    var arr = []
    var keyWord = e.detail.value

    for (var i = 0; i < that.data.listDeleteSearch.length; i++) {

      if (that.data.listDeleteSearch[i].PartnerName.indexOf(keyWord) >= 0 || that.data.listDeleteSearch[i].PartnerTel.indexOf(keyWord) >= 0) {
        arr.push(that.data.listDeleteSearch[i]);
      }
    }
    if (keyWord != null && keyWord != undefined && keyWord != '' && keyWord != ' ' && keyWord.length != 0) {
      that.setData({
        listDelete: arr,
      });
    } else {
      that.setData({
        listDelete: that.data.listDeleteSearch
      });
    }
  },


  //显示添加导游弹框
  addPartnerGuider: function () {
    getDataParnterGuider(this)
    this.setData({
      selectTagAdd: 1,
      selectTagGuider: 0
    });
  },
  //隐藏添加导游弹框
  hideModalAdd: function () {
    this.setData({
      selectTagAdd: 0,
    });
  },
  //将导游添加进合作导游
  AddPartnerGuider2: function (e) {
    var that = this
    var guiderName = e.currentTarget.dataset.namex
    var guiderID = e.currentTarget.dataset.idx
    wx: wx.showModal({
      title: '确定添加?',
      content: '确定将(' + guiderName + ')添加进合作导游?',
      showCancel: true,
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          ParnterGuiderAdd(that, guiderID)
        } else {

        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  //添加合作导游搜索
  inputsearchAdd: function (e) {
    var that = this
    var arr = []
    var keyWord = e.detail.value

    if (keyWord == '') {
      that.setData({
        listGuiderPartnerAdd: [],
      });
      return
    }

    for (var i = 0; i < that.data.listGuiderPartnerAddSearch.length; i++) {

      if (that.data.listGuiderPartnerAddSearch[i].sName.indexOf(keyWord) >= 0 || that.data.listGuiderPartnerAddSearch[i].sTel.indexOf(keyWord) >= 0) {
        arr.push(that.data.listGuiderPartnerAddSearch[i]);
      }
    }
    if (keyWord != null && keyWord != undefined && keyWord != '' && keyWord != ' ' && keyWord.length != 0) {
      if (arr.length == 0) {
        wx.showToast({
          title: '没有对应的导游',
          icon: 'none',
          duration: 1000,
        })
      }
      that.setData({
        listGuiderPartnerAdd: arr,
      });
    } else {
      that.setData({
        listGuiderPartnerAdd: that.data.listGuiderPartnerAddSearch
      });
    }
  },

  locate: function (e) {
    var dateEnd = e.currentTarget.dataset.idx
    var isopen = e.currentTarget.dataset.open
    console.log(dateEnd)
    var time1 = util.formatTime1(new Date())
    console.log(time1)
    if (dateEnd < time1) {
      this.showError('订单已过期')
      return
    }
    if (isopen == 0) {
      this.showError('该司机尚未开启定位功能')
      return
    }

    var that = this
    var DriverID = e.currentTarget.id
    wx.navigateTo({
      url: '../travelAgency/locate?IDD=' + that.data.IDD + '&DriverID=' + DriverID + '&retype=3',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  locateGuider: function (e) {
    var that = this
    var dateEnd = e.currentTarget.dataset.idx
    var isopen = e.currentTarget.dataset.open
    console.log(dateEnd)
    var time1 = util.formatTime1(new Date())
    console.log(time1)
    if (dateEnd < time1) {
      that.showError('订单已过期')
      return
    }
    if (isopen == 0) {
      that.showError('该导游尚未开启定位功能')
      return
    }
    var GuiderID = e.currentTarget.id
    wx.navigateTo({
      url: '../travelAgency/locate?IDD=' + that.data.IDD + '&DriverID=' + GuiderID + '&retype=4',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  locateChengke: function (e) {
    var that = this
    var dateEnd = e.currentTarget.dataset.idx
    var isopen = e.currentTarget.dataset.open
    console.log(dateEnd)
    var time1 = util.formatTime1(new Date())
    console.log(time1)
    if (dateEnd < time1) {
      that.showError('订单已过期')
      return
    }
    if (isopen == 0) {
      that.showError('该乘客尚未开启定位功能')
      return
    }
    var ChengkeID = e.currentTarget.id
    wx.navigateTo({
      url: '../travelAgency/locate?IDD=' + that.data.IDD + '&DriverID=' + ChengkeID + '&retype=5',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },


  showError: function (msg) {
    var that = this;
    that.setData({
      formError: true,
      errorMessage: msg
    });

    setTimeout(function () {
      that.setData({
        formError: false,
        errorMessage: '未知错误'
      });
    }, 2000);
  },






  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数
    var IDD1 = options.IDD;
    this.setData({
      IDD: IDD1,

    });
    billIDD = IDD1
    if (!IDD1) {
      this.setData({
        order_error: true
      });
    } else {
      //请求加载订单数据
      // getServiceData(this);
      // getServiceData2(this);

    }

    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winHeight: res.windowHeight
        });
      }
    });
  },

  //导游推送方法
  PushToCarGuider: function () {
    var that = this
    wx.showToast({
      title: '正在加载...',
      icon: 'loading',
      duration: 10000
    });
    console.log(that.data.GuiderTel)
    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: that.data.GuiderTel,
        title: '您有新的订单来了',
        content: '旅行社给您发送了一个新的订单'
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        // success
        // var data = tool.getRegularJson(res.data);
        var code = res.data.code;
        console.log(res);
        if (code == 0) {
          console.log('post推送请求成功')

        } else {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      },
      complete: function () {
        // complete
        wx.hideToast();
        wx.stopPullDownRefresh();
      }
    })
  },

  //cancel导游 司机推送方法 
  CancelPushToGuider: function (tel, iscancel) {
    var that = this
    var content1 = ''
    var content2 = ''
    if (iscancel == '0') {
      content1 = '您的订单已取消'
      content2 = '旅行社给您的订单发生了变更'
    } else {
      content1 = '您的订单已恢复'
      content2 = '旅行社给您的订单发生了变更'
    }
    console.log(content1, content2)
    console.log(that.data.GuiderTel)
    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: tel,
        title: content1,
        content: content2
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        // success
        // var data = tool.getRegularJson(res.data);
        var code = res.data.code;
        console.log(res);
        if (code == 0) {
          console.log('post推送请求成功')

        } else {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      },
      complete: function () {
      }
    })
  },
  oderStatusPush: function (status, tel) {
    var that = this
    var content = ''

    if (status == 0) {
      return
    }
    if (status == 1) {
      content = '用车方确认了一个订单'
    }
    if (status == 2) {
      content = '用车方取消了一个订单'
    }
    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: tel,
        title: '您的一个订单状态发生了改变',
        content: content
      },
      method: 'GET',
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        console.log(res)
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },
  //修改司机报价的推送方法
  changeDriverPricePush: function (price) {
    var that = this
    var title = '旅行社给您的订单报价已修改，请及时关注'
    var content = '报价已修改为:' + price
    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: that.data.DriverTel,
        title: title,
        content: content
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        // success
        // var data = tool.getRegularJson(res.data);
        var code = res.data.code;
        console.log(res);
        if (code == 0) {
          console.log('post推送请求成功')

        } else {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      },
    })
  },

  ChangeOrderPricePush: function (tel, price) {
    var that = this
    var title = '旅行社给您的订单报价已修改，请及时关注'
    var content = '报价已修改为:' + price
    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: tel,
        title: title,
        content: content
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        // success
        // var data = tool.getRegularJson(res.data);
        var code = res.data.code;
        console.log(res);
        if (code == 0) {
          console.log('post推送请求成功')

        } else {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    pricother = 1;
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    getServiceData(this);
    getServiceData2(this);
    getDataChengke(this);
    getDataGuider(this);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    getServiceData(this);
    getServiceData2(this);
    getDataChengke(this);
    getDataGuider(this);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  cancelpassenger: function (e) {
    var that = this
    wx: wx.showModal({
      title: '确定取消',
      content: '确定要取消这个乘客吗',
      showCancel: true,
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          var tel = e.currentTarget.dataset.tel
          that.cancelpassenger2(e, tel)
        } else {

        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  // 旅行社取消乘客
  cancelpassenger2: function (e, tel) {
    var that = this
    console.log(e)
    var userInfo = wx.getStorageSync('userInfo');
    console.log(userInfo)
    wx.request({
      url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddCoopPartners.ashx',
      data: {
        ID: userInfo.ID,
        PID: e.currentTarget.id,
        IDD: that.data.IDD,
        Type: 4,
        OpType: 1,
        Price: 0,
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        // success

        var data = tool.getRegularJson(res.data);
        var code = data.code;
        console.log(res);
        if (code == 0) {

          wx.showToast({
            title: '已取消',
            icon: 'success',
            duration: 1000
          })
          setTimeout(function deletesuccess() {
            getDataChengke(that)
          }, 1000);

          that.CancelPushToGuider(tel, 0)

          var pages = getCurrentPages()
          var backpage = pages[pages.length - 2]
          backpage.setData({
            backtag: 1,
          });
        } else {
          that.showError(data.msg)
        }
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },

  //changeDriverPrice2是用于修改的价格
  changepricedriver: function (e) {
    var that = this
    console.log(e)
    that.setData({
      hiddenDriver: false,
      changeDriverName: e.currentTarget.dataset.name,
      changeDriverPrice: e.currentTarget.dataset.price,
      changeDriverPrice2: e.currentTarget.dataset.price,
      changeDriverID: e.currentTarget.dataset.driverid,
      DriverTel: e.currentTarget.dataset.tel

    });
  },

  inputDriverPrice: function (e) {
    var that = this
    console.log(e)
    that.setData({
      changeDriverPrice: e.detail.value
    });
  },

  cancelDriverPrice: function () {
    var that = this
    that.setData({
      hiddenDriver: true,
      changeDriverName: '',
      changeDriverPrice: '',
      changeDriverPrice2: '',
      changeDriverID: ''
    });
  },

  confirmDriverPrice: function () {
    var that = this
    var userInfo = wx.getStorageSync('userInfo');
    console.log(userInfo)
    var price1 = that.data.changeDriverPrice
    var price2 = that.data.changeDriverPrice2
    if (price1 == price2) {
      that.showError('价格未改变，操作取消')
      that.cancelDriverPrice()
      return
    } else {
      wx.request({
        url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddCar.ashx',
        data: {
          methos: 'update',
          Tel: userInfo.Telphone,
          IDD: that.data.IDD,
          GID: that.data.changeDriverID,
          Price: price1
        },
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        // header: {}, // 设置请求的 header
        success: function (res) {
          if (res.statusCode == 404) {
            //接口加载失败
            console.log('加载接口错误');
            //隐藏Toast
            wx.hideToast();
            //显示错误信息
            that.showError('接口请求失败，请重试')
            return
          }
          // success
          var data = tool.getRegularJson(res.data);
          var code = data.code;
          console.log(res);
          if (code == 0) {
            that.cancelDriverPrice()
            wx.showToast({
              title: '修改成功',
              icon: 'success',
              duration: 1000
            })

            that.changeDriverPricePush(price1)

            var pages = getCurrentPages()
            var backpage = pages[pages.length - 2]
            backpage.setData({
              backtag: 1,
            });

          } else {
            that.showError(data.msg)
          }
        },
        fail: function () {
          // fail
        },
        complete: function () {
          // complete
          that.onPullDownRefresh();
        }
      })
    }
  }
})

function getServiceData(that) {
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  var userInfo = wx.getStorageSync('userInfo');
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/OrderInfo.ashx',
    data: {
      IDD: that.data.IDD,
      methd: '0'
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success

      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        that.setData({
          traveldetail: data.data[0],
        });
        //判断是否含费
        if (that.data.traveldetail.inclued == 0) {
          that.setData({
            checked: false,

          })
          pricother = 0
        } else {
          that.setData({
            checked: true,

          })
          pricother = 1
        }
        var arrdetail = that.data.traveldetail
        var Stime = arrdetail.UseCarStartTime.substring(11, 16)
        var Etime = arrdetail.UseCarEndTime.substring(11, 16)
        console.log(Stime, Etime)
        if (Stime == '00:00' && Etime == '23:59') {
          that.setData({
            StartTime: arrdetail.UseCarStartTime.substring(0, 10),
            EndTime: arrdetail.UseCarEndTime.substring(0, 10),
          })
        } else {
          that.setData({
            StartTime: arrdetail.UseCarStartTime.substring(0, 16),
            EndTime: arrdetail.UseCarEndTime.substring(0, 16),
          })
        }


      } else {
        that.setData({
          order_error: true
        });
        that.showError(data.msg)
      }
    },
    fail: function () {
      // fail
      that.setData({
        order_error: true
      });
    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function getServiceData2(that) {
  that.data.list = []
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  var username = wx.getStorageSync('username');
  var userpwd = wx.getStorageSync('password');
  wx.request({
    url: 'https://www.lanshuicar.com/Server/DriverPerson/GetDriverCarInfo.ashx',
    data: {
      idd: that.data.IDD,
      tel: username,
      pwd: userpwd
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success

      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        that.setData({
          list: that.data.list.concat(data.data),
        });
      } else {
        that.setData({
          order_error: true
        });
        that.showError(data.msg)
      }
    },
    fail: function () {
      // fail
      that.setData({
        order_error: true
      });
    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function changeOrderState(e, thiss) {
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgenUpdateOrderStatus.ashx',
    data: {
      IDD: billIDD,
      TrueStatus: e
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '修改成功',
        });
        getServiceData(thiss)
        //个人司机
        if (thiss.data.traveldetail.CarCompanyID == -1) {
          for (var i = 0; i < thiss.data.list.length; i++) {
            var tel = thiss.data.list[i].sTel
            thiss.oderStatusPush(e, tel)
          }

        }
        //车公司
        if (thiss.data.traveldetail.CarCompanyID > 0) {
          thiss.oderStatusPush(e, thiss.data.traveldetail.replyTel)
        }

        var pages = getCurrentPages()
        var backpage = pages[pages.length - 2]
        backpage.setData({
          backtag: 1,
        });

      } else {
        thiss.showError(data.msg)

      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function changePrice(thiss) {
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  console.log(thiss.data.price)
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/UpdateHopePrice.ashx',
    data: {
      IDD: billIDD,
      InClued: pricother,
      HopePrice: thiss.data.price
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '修改成功',
        });
        if (thiss.data.traveldetail.CarCompanyID > 0) {
          thiss.ChangeOrderPricePush(thiss.data.traveldetail.replyTel, thiss.data.price)
        }


        getServiceData(thiss)
      } else {
        thiss.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function cancelorhuifu(that, DriverID) {
  var username = wx.getStorageSync('username');
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddCar.ashx',
    data: {
      IDD: billIDD,
      methos: 'delete',
      Tel: username,
      GID: DriverID
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '修改成功',
        });
        getServiceData2(that)

        var pages = getCurrentPages()
        var backpage = pages[pages.length - 2]
        backpage.setData({
          backtag: 1,
        });

      } else {
        that.showError(data.msg)

      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}


function getDataChengke(that) {
  that.data.listChengke = [],
    wx.showToast({
      title: '正在加载...',
      icon: 'loading',
      duration: 10000
    });
  var userInfo = wx.getStorageSync('userInfo');
  console.log(userInfo);
  wx.request({
    url: 'https://www.lanshuicar.com/Server/GetCarsGuidersCusts.ashx',
    data: {
      OType: '1',
      IDD: that.data.IDD,
      PageSize: '200',
      UID: userInfo.ID,
      UType: '2',
      PageIndex: '1'
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success

      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        that.setData({
          listChengke: that.data.listChengke.concat(data.data),
        });
      } else {
        that.setData({
          order_error: true
        });
        that.showError(data.msg)
      }
    },
    fail: function () {
      // fail
      that.setData({
        order_error: true
      });
    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

//获取添加的乘客列表
function getDataChengkeAdd(that) {
  that.data.listChengkeAdd = []
  that.data.listChengkeAddSearch = []
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  var userInfo = wx.getStorageSync('userInfo');
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CooPeratePartners.ashx',
    data: {
      PageSize: '200',
      PageIndex: '1',
      Type: '1',
      ID: userInfo.ID,
      CType: '4',
      Info: '1'
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success

      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        that.setData({
          // listChengkeAdd: that.data.listChengkeAdd.concat(data.data),
          listChengkeAddSearch: that.data.listChengkeAddSearch.concat(data.data)
        });
      } else {
        that.setData({
          order_error: true
        });
        that.showError(data.msg)
      }
    },
    fail: function () {
      // fail
      that.setData({
        order_error: true
      });
    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}
//把乘客拉进订单
function pullChengkeToOrder(that) {
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  var userInfo = wx.getStorageSync('userInfo');
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddCoopPartners.ashx',
    data: {
      ID: userInfo.ID,
      PID: that.data.ChengkeID,
      Type: '4',
      OpType: '0',
      Price: that.data.ChengkePrice,
      IDD: that.data.IDD
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success

      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '拉入成功',
        })
        that.PushToCarGuider()

        getDataChengke(that)

        var pages = getCurrentPages()
        var backpage = pages[pages.length - 2]
        backpage.setData({
          backtag: 1,
        });
      } else {

        that.showError(data.msg)
      }
    },
    fail: function () {
      // fail

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function getDataGuider(that) {
  that.data.listGuider = [],
    wx.showToast({
      title: '正在加载...',
      icon: 'loading',
      duration: 10000
    });
  var userInfo = wx.getStorageSync('userInfo');
  console.log(userInfo);
  wx.request({
    url: 'https://www.lanshuicar.com/Server/GetCarsGuidersCusts.ashx',
    data: {
      Tel: userInfo.Telphone,
      IDD: that.data.IDD,
      OType: '2',
      PageIndex: '1',
      PageSize: '200',
      UType: '2',
      UID: userInfo.ID
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success

      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        that.setData({
          listGuider: that.data.listGuider.concat(data.data),
        });
      } else {
        that.setData({
          order_error: true
        });
        that.showError(data.msg)
      }
    },
    fail: function () {
      // fail
      that.setData({
        order_error: true
      });
    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function cancelORGuider(that, GuiderID) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddGuiders.ashx',
    data: {
      methos: 'delete',
      Tel: userInfo.Telphone,
      IDD: that.data.IDD,
      GID: GuiderID

    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '修改成功',
        });
        getDataGuider(that)

        var pages = getCurrentPages()
        var backpage = pages[pages.length - 2]
        backpage.setData({
          backtag: 1,
        });

      } else {

        that.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}


function GuiderChangePriceFun(that) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddGuiders.ashx',
    data: {
      methos: 'update',
      Tel: userInfo.Telphone,
      IDD: that.data.IDD,
      GID: that.data.GuiderIDChangePrice,
      Price: that.data.GuiderChangePrice
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '修改报价成功',
        });

        that.changeDriverPricePush(that.data.GuiderChangePrice)

        getDataGuider(that)


        var pages = getCurrentPages()
        var backpage = pages[pages.length - 2]
        backpage.setData({
          backtag: 1,
        });

      } else {

        that.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function getDataGuiderAdd(that) {
  that.data.listGuiderAdd = []
  that.data.listGuiderAddSearch = []
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CooPeratePartners.ashx',
    data: {
      PageSize: '200',
      PageIndex: '1',
      Type: '1',
      ID: userInfo.ID,
      CType: '2',
      Info: '0'
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        that.setData({
          listGuiderAdd: that.data.listGuiderAdd.concat(data.data),
          listGuiderAddSearch: that.data.listGuiderAddSearch.concat(data.data)
        })

      } else {
        that.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function pullGuiderToOder(that) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddGuiders.ashx',
    data: {
      methos: 'add',
      Tel: userInfo.Telphone,
      IDD: that.data.IDD,
      GID: that.data.GuiderIDNew,
      Price: that.data.GuiderPrice
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '导游添加成功',
        })
        getDataGuider(that)
        that.PushToCarGuider()
      } else {
        that.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function deletePartnerGuider(that, guiderID) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddCoopPartners.ashx',
    data: {
      ID: userInfo.ID,
      PID: guiderID,
      Type: '2',
      OpType: '1',
      IDD: that.data.IDD
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '导游移出成功',
        })
        that.setData({
          selectTagDelete: 0
        })
      } else {
        that.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function getDataParnterGuider(that) {
  that.data.listGuiderPartnerAdd = []
  that.data.listGuiderPartnerAddSearch = []
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CooPeratePartners.ashx',
    data: {
      PageSize: '200',
      PageIndex: '1',
      Type: '1',
      ID: userInfo.ID,
      CType: '2',
      Info: '1'
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        that.setData({
          // listGuiderPartnerAdd: that.data.listGuiderPartnerAdd.concat(data.data),
          listGuiderPartnerAddSearch: that.data.listGuiderPartnerAddSearch.concat(data.data)
        })

      } else {
        that.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}

function ParnterGuiderAdd(that, guiderID) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/AgencyServer/AgencyAddCoopPartners.ashx',
    data: {
      ID: userInfo.ID,
      PID: guiderID,
      Type: '2',
      OpType: '0'
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      if (res.statusCode == 404) {
        //接口加载失败
        console.log('加载接口错误');
        //隐藏Toast
        wx.hideToast();
        //显示错误信息
        that.showError('接口请求失败，请重试')
        return
      }
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '添加合作导游成功',
        })
        that.setData({
          selectTagAdd: 0
        })
      } else {
        that.showError(data.msg)
      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })


}
